package conchmusic.conchmusicclient.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import java.util.List;

import conchmusic.conchmusicclient.R;
import conchmusic.conchmusicclient.pojo.Song;

/**
 * Created by Administrator on 2017/4/14.
 */

public class ManySelectAdapter extends BaseAdapter {
    private Context context;
    private List<Song> listItems;
    private LayoutInflater listContainer;
    private List<Integer> checkList;
    public ManySelectAdapter(Context context, List<Song> listItems,List<Integer> checkList) {
        this.context = context;
        this.listItems = listItems;
        this.checkList=checkList;
        listContainer=LayoutInflater.from(context);
    }
    public final class ManyListItemView{                //自定义控件集合
        public TextView localSongName;
        public TextView LocalSinger;
        public CheckBox checkBox;
    }

    @Override
    public int getCount() {
        return listItems.size();
    }

    @Override
    public Object getItem(int position) {
        return listItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ManyListItemView  listItemView = null;

        if (convertView == null) {
            listItemView = new ManyListItemView();
            convertView = listContainer.inflate(R.layout.many_select_basic, null);
            listItemView.localSongName=(TextView) convertView.findViewById(R.id.many_select_songname);
            listItemView.LocalSinger=(TextView) convertView.findViewById(R.id.many_select_singer);
            listItemView.checkBox=(CheckBox) convertView.findViewById(R.id.checkbox_many_select);
            convertView.setTag(listItemView);
        }else {
            listItemView = (ManyListItemView)convertView.getTag();
        }
        List<String> artistNamesList=listItems.get(position).getArtistNames();
        String artistName="";
        for(String artist:artistNamesList){
            artistName=artist+" ";
        }
        listItemView.LocalSinger.setText(artistName);
        listItemView.localSongName.setText((String) listItems.get(position).getTitle());
        listItemView.checkBox.setChecked((checkList.get(position)==1));
        return convertView;
    }
}
